import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/card_task',
    name: 'card_task',
    component: () => import('../views/Cards/card_task.vue')

  },
  {
    path: '/card_rz02',
    name: 'card_rz02',
    component: () => import('../views/Cards/cards_rz02.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../components/login.vue')
  }, {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/home.vue'), children: [
      {
        path: '/gold',
        name: 'gold',
        component: () => import('../views/home_child/gold.vue')
      }, {
        path: '/office',
        name: 'office',
        component: () => import('../views/home_child/office.vue'), children: [
          {
            path: '/office/gzt', name: 'gzt', component: () => import('../views/office_child/office_gzt.vue'),
          }, {
            path: '/office/rc', name: 'rc', component: () => import('../views/office_child/office_rc.vue')
          },
          {
            path: '/office/task', name: 'task', component: () => import('../views/office_child/office_task.vue')
          },
          {
            path: '/office/gs', name: 'gs', component: () => import('../views/office_child/office_g.vue')
          },
          {
            path: '/office/rz', name: 'rz', component: () => import('../views/office_child/office_rz.vue')
          },
          {
            path: '/office/sp', name: 'sp', component: () => import('../views/office_child/office_sp.vue')
          },
          {
            path: '/office/tellphone', name: 'tellphone', component: () => import('../views/office_child/office_photo.vue')
          }
        ]
      },
      {
        path: '/me', name: 'name', component: () => import('../views/home_child/me.vue')
      },
      {
        path: '/shoplk',
        name: 'shoplk',
        component: () => import('../views/home_child/shoplk.vue')
      }, {
        path: '/taskall',
        name: 'taskall',
        component: () => import('../views/home_child/taskall.vue')
      }
    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


// router.beforeEach((to, from, next) => {
//   // 如果要访问的页面不是 /login，校验登录状态
//   // 如果没有登录，则跳转到登录页面
//   // 如果登录了，则允许通过
//   // 允许通过
//   // next()

//   const user = window.localStorage.getItem('token')

//   // 校验非登录页面的登录状态
//   if (to.path !== '/login') {
//     if (user) {
//       // 已登录，允许通过
//       next()
//     } else {
//       // 没有登录，跳转到登录页面
//       next('/login')
//     }
//   } else {
//     // 登录页面，正常允许通过
//     next()
//   }
// })



export default router
